﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Monocle.DataProvider;
using Monocle.Models.ControlPanel;

namespace Monocle.Controllers
{
    public class ControlPanelController : Controller
    {
        public ActionResult Menu()
        {
            return View();
        }

        public ActionResult ChangePassword(IDataProvider dataProvider)
        {
            throw new NotImplementedException();
            //var viewModel = new ChangePasswordViewModel();
            //viewModel.Email = HttpContext.User.Identity.Name;
            //return View(viewModel);
        }

        [HttpPost]
        public ActionResult ChangePassword(ChangePasswordViewModel viewModel, IDataProvider dataProvider)
        {
            throw new NotImplementedException();
            //if (!ModelState.IsValid)
            //{
            //    //The viewmodel is not valid. Return input and the view
            //    return View(viewModel);
            //}
            //else
            //{
            //    var validation = new Security().ValidatePassword(viewModel.Password);
            //    if (validation.Count > 0)
            //    {
            //        foreach (var item in validation)
            //        {
            //            switch (item)
            //            {
            //                case Enums.PasswordRules.Length:
            //                    var errorString = mCMS.Resources.Resources.PasswordValidation_Length.Replace(
            //                        "%[length]", ConfigurationManager.AppSettings["PasswordMinimumLength"]);
            //                    ModelState.AddModelError("", errorString); //TODO: String replace the length
            //                    break;
            //                case Enums.PasswordRules.LowerCase:
            //                    ModelState.AddModelError("", mCMS.Resources.Resources.PasswordValidation_LowerCase);
            //                    break;
            //                case Enums.PasswordRules.NonAlphaNumerical:
            //                    ModelState.AddModelError("",
            //                                             mCMS.Resources.Resources.PasswordValidation_NonAlphaNumerical);
            //                    break;
            //                case Enums.PasswordRules.Numerical:
            //                    ModelState.AddModelError("", mCMS.Resources.Resources.PasswordValidation_Numerical);
            //                    break;
            //                case Enums.PasswordRules.UpperCase:
            //                    ModelState.AddModelError("", mCMS.Resources.Resources.PasswordValidation_UpperCase);
            //                    break;
            //            }
            //        }
            //        return View(viewModel);
            //    }

            //    try
            //    {
            //        if (!dataProvider.ChangePassword(viewModel.Email, viewModel.OldPassword, viewModel.Password))
            //            ModelState.AddModelError("", "SQL layer passwordvalidation failed");

            //        //Redirect the user to somewhere else. Could be a success page

            //        ViewBag.Status = mCMS.Resources.Resources.Generic_Saved;
            //        return View(viewModel);
            //    }
            //    catch (Exception e)
            //    {
            //        ModelState.AddModelError("", "En fejl er opstået: " + e.Message);
            //        return View(viewModel);
            //    }

            //}
        }
    }
}
